package com.kiliter.utils;


import com.alibaba.fastjson.JSONObject;
import com.aliyun.dysmsapi20170525.Client;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.aliyun.tea.*;
import com.aliyun.dysmsapi20170525.*;
import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.teaopenapi.*;
import com.aliyun.teaopenapi.models.*;

/**
 * @ClassName zhangjl
 * @date 2021/6/1 11:53
 * @Version 1.0
 */
@Component
public class SmsUtil {

   @Value("${aliyun.sms.accessKeyId}")
   private  String accessKeyId;
   @Value("${aliyun.sms.accessKeySecret}")
   private  String accessKeySecret;
   @Value("${aliyun.sms.template_code}")
   private  String template_code;
   @Value("${aliyun.sms.sign_name}")
   private  String sign_name;

   public   Client createClient() throws Exception {
      Config config = new Config()
              // 您的AccessKey ID
              .setAccessKeyId(accessKeyId)
              // 您的AccessKey Secret
              .setAccessKeySecret(accessKeySecret);
      // 访问的域名
      config.endpoint = "dysmsapi.aliyuncs.com";
      return new Client(config);
   }

   public SendSmsResponse SendSms(String json) throws Exception {
      Client client = createClient();
      SendSmsRequest sendSmsRequest = new SendSmsRequest()
              .setPhoneNumbers("13355624709")
              .setSignName(sign_name)
              .setTemplateCode(template_code)
              .setTemplateParam(json);
      SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
      System.out.println(sendSmsResponse.getBody().getMessage());
      return sendSmsResponse;
   }

}